#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/7/7 14:11
# @Author  : CoderCharm
# @File    : views.py
# @Software: PyCharm
# @Desc    :
"""

"""
from datetime import timedelta
from typing import Any, List, Union

from sqlalchemy.orm import Session
from fastapi import APIRouter, Depends,Query
from api.api_v1.rbacm.schemas import role_schema
from core import security

from api.common import deps
from api.utils import response_code
from api.common.logger import logger

from api.models import auth
from core.config import settings

from .schemas import user_schema, token_schema

from .crud import curd_user, curd_role,curd_resource,curd_workflow

router = APIRouter()


#设置工作流属性
@router.get("/wfsetparams", summary="设置工作流属性")
async def wf_setparams(
        db: Session = Depends(deps.get_db),
        workid:int=0,
        params:str=""
):
    print("&&&&&")
    print(workid)
    print(params)
    # logger.info(f"添加角色->用户id:,角色名:{role_info.name}")
    curd_workflow.wf_setpromition(db=db, wid=workid,params=params)
    return response_code.resp_200(message="设置成功")

#通过角色id获取对应的资源列表
@router.post("/setworkflowaudit",summary="通过角色id设置对应的资源列表")
async def setworkflowaudit(
    db: Session = Depends(deps.get_db),
    id:int=0,
    idlist:str=""
):
   print(id)
   return 'ok'
   idlist = eval(idlist)
   res = sorted(idlist.items(),key=lambda item:item[1],reverse=True)
   print(res)
   ids = [i[0] for i in res]
   print(ids)
   return 'ok'
   

